package com.zhaojonhy.zhaopangwb.utils;

import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;

import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.zhaojonhy.zhaopangwb.R;
import com.zhaojonhy.zhaopangwb.bean.User;
import com.zhaojonhy.zhaopangwb.utils.ImageOptHelper;

/**
 * Created by Administrator on 2016/9/12.
 */
public class BaseApplication extends Application{

    public static User currentUser ;

    @Override
    public void onCreate() {
        super.onCreate();

        initImageloader(this) ;
    }
    //Imageloader 初始化图片处理
    private void initImageloader(Context context){
        DisplayImageOptions options;
        options = new DisplayImageOptions.Builder()
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .showImageOnLoading(R.drawable.timeline_image_loading)
                .showImageForEmptyUri(R.drawable.timeline_image_loading)//图片Uri为空或是错误的时候显示的图片
                .showImageOnFail(R.drawable.timeline_image_failure)//失败的图片
                .considerExifParams(true)
                .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .resetViewBeforeLoading(false)
                .displayer(new RoundedBitmapDisplayer(20))
                .displayer(new FadeInBitmapDisplayer(0))
                .build();
        ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(context)
                .threadPriority(Thread.NORM_PRIORITY - 2) // default 设置当前线程的优先级
                // default为使用HASHCODE对UIL进行加密命名， 还可以用MD5(new Md5FileNameGenerator())加密
                .diskCacheFileNameGenerator(new Md5FileNameGenerator())
                .tasksProcessingOrder(QueueProcessingType.FIFO) // default
                .memoryCache(new WeakMemoryCache())
                .defaultDisplayImageOptions(options)
                .writeDebugLogs()//打印log信息
                .build() ;
        //配置好ImageLoaderConfiguration，一定不要忘记进行初始化操作（一般在application中进行初始化）
        ImageLoader.getInstance().init(configuration);
    }
}
